//
//  CZStatusTableViewCell.swift
//  weiBo
//
//  Created by apple on 16/5/14.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import SnapKit

class CZStatusTableViewCell: UITableViewCell {

    var toolBarTop :Constraint?
    
    var statusViewModel: CZStatusViewModel? {
        didSet {
            statusOriginalView.statusViewModel = statusViewModel
            statusRetweetView.statusViewModel = statusViewModel
            statusToolBar.statusViewModel = statusViewModel
            //设置转发微博约束
            //卸载约束
            toolBarTop?.uninstall()
            if statusViewModel?.status?.retweeted_status != nil {
                
                statusRetweetView.hidden = false
                statusToolBar.snp_makeConstraints(closure: { (make) -> Void in
                    self.toolBarTop = make.top.equalTo(statusRetweetView.snp_bottom).constraint
                })
            }else{
                statusRetweetView.hidden = true
                
                 statusToolBar.snp_makeConstraints(closure: { (make) -> Void in
                   self.toolBarTop = make.top.equalTo(statusOriginalView.snp_bottom).constraint
                })
            
            }
            
        }
        
    }
    
    //原始微博
    private lazy var statusOriginalView : CZStatusOriginalView = CZStatusOriginalView()
    //转发微博
    private lazy var statusRetweetView: CZStatusRetweetView = CZStatusRetweetView()
    //底部ToolBar
    private lazy var statusToolBar: CZStatusToolBar = CZStatusToolBar()
   
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    private func setUpUI() {
        contentView.addSubview(statusOriginalView)
        contentView.addSubview(statusRetweetView)
        contentView.addSubview(statusToolBar)
        
        
        statusOriginalView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView)
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
        }
        statusRetweetView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(statusOriginalView.snp_bottom)
            make.left.equalTo(contentView)
            make.right.equalTo(contentView)
        }
        statusToolBar.snp_makeConstraints { (make) -> Void in
            self.toolBarTop = make.top.equalTo(statusRetweetView.snp_bottom).constraint
            make.left.equalTo(contentView)
            make.right.equalTo(contentView)
            make.height.equalTo(40)
            
        }
    
        contentView.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(statusToolBar)
            make.leading.equalTo(self)
            make.trailing.equalTo(self)
            make.top.equalTo(self)
        }
    
    
    }
    
    
}
